using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace WindowsApplication1
{
	/// <summary>
	/// Summary description for stu_id.
	/// </summary>
	public class stu_id : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtsid;
		private System.Windows.Forms.Button btnsearch;
		private System.Windows.Forms.DataGrid grdsid;
		private System.Windows.Forms.Button btnclose;
		private System.Windows.Forms.LinkLabel linkLabel1;
		private System.Windows.Forms.GroupBox gpid;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox txtname;
		private System.Windows.Forms.Button btnmodify;
		private System.Windows.Forms.Button btnupdate;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Panel pnlstudent;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Panel pnlcourse;
		private System.Windows.Forms.TextBox txtfrom;
		private System.Windows.Forms.TextBox txtto;
		private System.Windows.Forms.Button btnsearch1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public stu_id()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}
		private int no1;
		public stu_id(int no)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
		no1=no;

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.txtsid = new System.Windows.Forms.TextBox();
			this.btnsearch = new System.Windows.Forms.Button();
			this.grdsid = new System.Windows.Forms.DataGrid();
			this.btnclose = new System.Windows.Forms.Button();
			this.linkLabel1 = new System.Windows.Forms.LinkLabel();
			this.gpid = new System.Windows.Forms.GroupBox();
			this.txtname = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.btnmodify = new System.Windows.Forms.Button();
			this.btnupdate = new System.Windows.Forms.Button();
			this.pnlcourse = new System.Windows.Forms.Panel();
			this.btnsearch1 = new System.Windows.Forms.Button();
			this.txtto = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.txtfrom = new System.Windows.Forms.TextBox();
			this.pnlstudent = new System.Windows.Forms.Panel();
			((System.ComponentModel.ISupportInitialize)(this.grdsid)).BeginInit();
			this.gpid.SuspendLayout();
			this.pnlcourse.SuspendLayout();
			this.pnlstudent.SuspendLayout();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(24, 19);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(41, 26);
			this.label1.TabIndex = 0;
			this.label1.Text = "Sid";
			// 
			// txtsid
			// 
			this.txtsid.Location = new System.Drawing.Point(80, 19);
			this.txtsid.Name = "txtsid";
			this.txtsid.Size = new System.Drawing.Size(72, 20);
			this.txtsid.TabIndex = 1;
			this.txtsid.Text = "";
			this.txtsid.TextChanged += new System.EventHandler(this.txtsid_TextChanged);
			// 
			// btnsearch
			// 
			this.btnsearch.Location = new System.Drawing.Point(600, 25);
			this.btnsearch.Name = "btnsearch";
			this.btnsearch.Size = new System.Drawing.Size(88, 25);
			this.btnsearch.TabIndex = 2;
			this.btnsearch.Text = "Search";
			this.btnsearch.Click += new System.EventHandler(this.btnsearch_Click);
			// 
			// grdsid
			// 
			this.grdsid.DataMember = "";
			this.grdsid.Enabled = false;
			this.grdsid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.grdsid.Location = new System.Drawing.Point(5, 195);
			this.grdsid.Name = "grdsid";
			this.grdsid.Size = new System.Drawing.Size(660, 205);
			this.grdsid.TabIndex = 3;
			this.grdsid.Visible = false;
			this.grdsid.Navigate += new System.Windows.Forms.NavigateEventHandler(this.grdsid_Navigate);
			// 
			// btnclose
			// 
			this.btnclose.Location = new System.Drawing.Point(320, 460);
			this.btnclose.Name = "btnclose";
			this.btnclose.Size = new System.Drawing.Size(88, 28);
			this.btnclose.TabIndex = 4;
			this.btnclose.Text = "Close";
			this.btnclose.Click += new System.EventHandler(this.btnclose_Click);
			// 
			// linkLabel1
			// 
			this.linkLabel1.Location = new System.Drawing.Point(180, 20);
			this.linkLabel1.Name = "linkLabel1";
			this.linkLabel1.Size = new System.Drawing.Size(84, 23);
			this.linkLabel1.TabIndex = 5;
			this.linkLabel1.TabStop = true;
			this.linkLabel1.Text = "Forgot id";
			this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
			// 
			// gpid
			// 
			this.gpid.Controls.AddRange(new System.Windows.Forms.Control[] {
																			   this.txtname,
																			   this.label2});
			this.gpid.Location = new System.Drawing.Point(275, 10);
			this.gpid.Name = "gpid";
			this.gpid.Size = new System.Drawing.Size(309, 56);
			this.gpid.TabIndex = 6;
			this.gpid.TabStop = false;
			this.gpid.Visible = false;
			// 
			// txtname
			// 
			this.txtname.Location = new System.Drawing.Point(154, 19);
			this.txtname.Name = "txtname";
			this.txtname.Size = new System.Drawing.Size(117, 20);
			this.txtname.TabIndex = 8;
			this.txtname.Text = "";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(14, 19);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(117, 26);
			this.label2.TabIndex = 7;
			this.label2.Text = "Student Name";
			// 
			// btnmodify
			// 
			this.btnmodify.Location = new System.Drawing.Point(115, 460);
			this.btnmodify.Name = "btnmodify";
			this.btnmodify.Size = new System.Drawing.Size(88, 28);
			this.btnmodify.TabIndex = 7;
			this.btnmodify.Text = "Modify";
			this.btnmodify.Visible = false;
			this.btnmodify.Click += new System.EventHandler(this.btnmodify_Click);
			// 
			// btnupdate
			// 
			this.btnupdate.Location = new System.Drawing.Point(220, 460);
			this.btnupdate.Name = "btnupdate";
			this.btnupdate.Size = new System.Drawing.Size(88, 28);
			this.btnupdate.TabIndex = 8;
			this.btnupdate.Text = "Update";
			this.btnupdate.Visible = false;
			this.btnupdate.Click += new System.EventHandler(this.btnupdate_Click);
			// 
			// pnlcourse
			// 
			this.pnlcourse.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.btnsearch1,
																					this.txtto,
																					this.label5,
																					this.label4,
																					this.label3,
																					this.txtfrom});
			this.pnlcourse.Location = new System.Drawing.Point(15, 105);
			this.pnlcourse.Name = "pnlcourse";
			this.pnlcourse.Size = new System.Drawing.Size(620, 75);
			this.pnlcourse.TabIndex = 0;
			this.pnlcourse.Paint += new System.Windows.Forms.PaintEventHandler(this.pnlcourse_Paint);
			// 
			// btnsearch1
			// 
			this.btnsearch1.Location = new System.Drawing.Point(475, 15);
			this.btnsearch1.Name = "btnsearch1";
			this.btnsearch1.Size = new System.Drawing.Size(87, 26);
			this.btnsearch1.TabIndex = 5;
			this.btnsearch1.Text = "Search";
			this.btnsearch1.Click += new System.EventHandler(this.btnsearch1_Click);
			// 
			// txtto
			// 
			this.txtto.Location = new System.Drawing.Point(305, 20);
			this.txtto.Name = "txtto";
			this.txtto.Size = new System.Drawing.Size(117, 20);
			this.txtto.TabIndex = 4;
			this.txtto.Text = "";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(100, 50);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(117, 19);
			this.label5.TabIndex = 3;
			this.label5.Text = "mm/dd/yyyy";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(250, 20);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(40, 20);
			this.label4.TabIndex = 2;
			this.label4.Text = "To";
			this.label4.Click += new System.EventHandler(this.label4_Click);
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(15, 19);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(65, 26);
			this.label3.TabIndex = 0;
			this.label3.Text = "From";
			// 
			// txtfrom
			// 
			this.txtfrom.Location = new System.Drawing.Point(95, 20);
			this.txtfrom.Name = "txtfrom";
			this.txtfrom.Size = new System.Drawing.Size(117, 20);
			this.txtfrom.TabIndex = 1;
			this.txtfrom.Text = "";
			// 
			// pnlstudent
			// 
			this.pnlstudent.Controls.AddRange(new System.Windows.Forms.Control[] {
																					 this.btnsearch,
																					 this.label1,
																					 this.txtsid,
																					 this.linkLabel1,
																					 this.gpid});
			this.pnlstudent.Location = new System.Drawing.Point(0, 15);
			this.pnlstudent.Name = "pnlstudent";
			this.pnlstudent.Size = new System.Drawing.Size(725, 75);
			this.pnlstudent.TabIndex = 9;
			// 
			// stu_id
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.AutoScroll = true;
			this.ClientSize = new System.Drawing.Size(791, 562);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnupdate,
																		  this.btnmodify,
																		  this.btnclose,
																		  this.pnlstudent,
																		  this.pnlcourse,
																		  this.grdsid});
			this.Name = "stu_id";
			this.Text = " Retrieve Student Details";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.Load += new System.EventHandler(this.stu_id_Load);
			((System.ComponentModel.ISupportInitialize)(this.grdsid)).EndInit();
			this.gpid.ResumeLayout(false);
			this.pnlcourse.ResumeLayout(false);
			this.pnlstudent.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		SqlConnection con;
		SqlDataAdapter da;
		DataSet ds;
		SqlCommandBuilder scmd;

		private void btnsearch_Click(object sender, System.EventArgs e)
		{
			grdsid.Visible=true;
			btnmodify.Visible=true;
			btnupdate.Visible=false;
			grdsid.Enabled=false;
            con = new SqlConnection();
            con.ConnectionString = "Data Source=ss.cs.luc.edu;Initial Catalog=PrepDB;User ID=ueshwara; pwd=p47807";
            con.Open();	
			if(gpid.Visible==false)
			{
				da=new SqlDataAdapter("Select * from student_details  where stu_id='" + txtsid.Text + "' ",con);
				ds=new DataSet();
				da.Fill(ds,"student_details");
				grdsid.DataSource=ds.Tables[0];
			}
			else
			{
                con = new SqlConnection();
                con.ConnectionString = "Data Source=ss.cs.luc.edu;Initial Catalog=PrepDB;User ID=ueshwara; pwd=p47807";
                con.Open();	
				da=new SqlDataAdapter("Select * from student_details where student_name='" + txtname.Text + "' ",con);
				ds=new DataSet();
				da.Fill(ds,"student_details");
				grdsid.DataSource=ds.Tables[0];
			}
            		
		}

		private void btnclose_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
		{
			txtsid.Text="";
			gpid.Visible=true;
		}

		private void btnmodify_Click(object sender, System.EventArgs e)
		{
		
			btnupdate.Visible=true;
			grdsid.Enabled=true;

		}

		private void txtsid_TextChanged(object sender, System.EventArgs e)
		{
		gpid.Visible=false;
		}

		private void btnupdate_Click(object sender, System.EventArgs e)
		{
			grdsid.DataSource=ds.Tables[0];
			scmd=new SqlCommandBuilder(da);
			da.Update(ds,"student_details");
			MessageBox.Show("Record Updated");
		}

		private void stu_id_Load(object sender, System.EventArgs e)
		{
			switch(no1)
			{
				case 0:
					pnlstudent.Visible=true;
					pnlcourse.Visible =false;
					break;
				case 1:
					pnlcourse.Visible =true;
					pnlstudent.Visible=false;
					
					break;
			}
		}

		private void label4_Click(object sender, System.EventArgs e)
		{
		
		}

		private void btnsearch1_Click(object sender, System.EventArgs e)
		{
			grdsid.Visible=true;
			grdsid.Enabled=true;
            con = new SqlConnection();
            con.ConnectionString = "Data Source=ss.cs.luc.edu;Initial Catalog=PrepDB;User ID=ueshwara; pwd=p47807";
            con.Open();	
			da=new SqlDataAdapter("Select * from student_details where doj between '" + txtfrom.Text + "' and '" + txtto.Text + "' ",con);
			//da1=new SqlDataAdapter("Select * from personaldetails where stu_id='" + txtsid.Text + "' ",con);

			ds=new DataSet();
			
			da.Fill(ds,"student_details");
			//da1.Fill(ds);
			grdsid.DataSource=ds.Tables[0];
		}

		private void pnlcourse_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
		
		}

		private void grdsid_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
		{
		
		}
	}
}
